home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / STRNICMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  756 b   |  32 lines

  1. /* strnicmp.c From TC Bible page 292  Use strncmp to compare a specified
  2. number of characters of two strings without regard to case */
  3.  
  4. #include <stdio.h>
  5. #include <string.h>
  6. main()
  7. {
  8.     int len, result;
  9.     char str1[80], str2[80];
  10.     printf("Enter a string: ");
  11.     gets(str1);
  12.     printf("Enter a string to compare with first: ");
  13.     gets(str2);
  14.     printf("How many characters to compare:");
  15.     scanf(" %d", &len);
  16.     printf("Based on case insensitive comparison of the first \
  17.     %d characters\n", len);
  18.     result = strnicmp(str1, str2, len);
  19.     if (result == 0)
  20.     {
  21.         printf("\"%s\" == \"%s\"\n", str1, str2);
  22.     }
  23.     if (result < 0)
  24.     {
  25.         printf("\"%s\" < \"%s\"\n", str1, str2);
  26.     }
  27.     if (result > 0)
  28.     {
  29.         printf("\"%s\" > \"%s\"\n", str1, str2);
  30.     }
  31. }
  32.